package redis;

import java.util.List;
import org.junit.Test;

import redis.clients.jedis.Jedis;

public class TestList {
	static Jedis jedis = null;

    static {
        jedis = new Jedis("192.168.79.131", 6379);//redis服务器地址与端口号
        jedis.auth("211125");
    }
    
    // 测试Java做为客户端连接redis
    public static void main(String[] args) {
    	System.out.println("服务启动..."+jedis.ping());
    	jedis.flushDB();
    }
    
    // 7.5.4 操作列表
    @Test
    public void lpushTest() {
    	Long lpush = jedis.lpush("userlist", "0311", "0309","0310","0312");
    	System.out.println("-----"+lpush);
    }

    @Test
    public void rpushTest() {
        Long lpush = jedis.rpush("userlist", "u03");
        System.out.println("-----"+lpush);
    }
    @Test
    public void lrangeTest() {
    	List<String> values = jedis.lrange("userlist", 0, -1);
    	System.out.println(values);
    }
    
    @Test
    public void lindexTest() {
    	String value = jedis.lindex("userlist", 2);
    	System.out.println(value);
    }
    
    @Test
    public void rpopTest() {
    	String value = jedis.lpop("userlist");
    	System.out.println(value);
    }
    
    @Test
    public void llenTest() {
    	Long len = jedis.llen("userlist");
    	System.out.println(len);
    }
    
    @Test
    public void lremTest() {
    	//从list的表头开始向表尾搜索，移除搜索到的第1个值为red的元素
    	Long result = jedis.lrem("userlist",0,"u03");
    	System.out.println(result);
    }
}
